import Paging from '../../../wxjs/Paging.js'
import navToNext from '../../../wxjs/navToNext.js'
const app = getApp();
var pag = new Paging();

var data = {
  xhx_images: app.xhx_images,
  xhx_route: app.xhx_route,
};

var currentPage = {
  data,
  reqUrl: app.serAddrs.getLectureOrderUserList,
  onLoad,
  clickFollow,
};

var page = Object.assign(pag.func(), navToNext, currentPage);

Page(page)

function onLoad(options) {
  const that = this;
  const uuid = options && options.uuid || '';
  const count = options && options.count || 0;
  const stock = options && options.stock || 0;

  wx.setNavigationBarTitle({
    title: `已预约${count}/${stock}`,
  })

  that.setData({
    uuid
  })
  that.listParams.uuid = uuid;
  // 初始化
  that.pageListInit();
}

function clickFollow(event) {
  const that = this;
  var index = event.currentTarget.dataset.index;
  let lists = that.data.lists || [];
  let focusStatus = lists[index].focusStatus;
  let serAddr = "addFocus";

  var myInfo = app.isNavigateToLogin();
  if (!myInfo) return;

  myInfo = app.isNavigateToBind();
  if (!myInfo) return;

  if (focusStatus == 1) serAddr = "delFocus";

  var reqData = {
    focusAccount: lists[index].userId,
  };

  app.middleware.requestAjax({
    serAddr: app.serAddrs[serAddr],
    data: reqData,
    success: function (res) {
      lists[index].focusStatus = lists[index].focusStatus==1?0:1;
      that.setData({
        lists
      })
    },
    fail: function (res) {
      app.middleware.showToast(res && res.msg || "操作失败");
      // 初始化
      // that.pageListInit();
    }
  })
}